package input;


import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.MouseLookHandler;
import com.jme.input.action.KeyBackwardAction;
import com.jme.input.action.KeyForwardAction;
import com.jme.input.action.KeyLookDownAction;
import com.jme.input.action.KeyLookUpAction;
import com.jme.input.action.KeyRotateLeftAction;
import com.jme.input.action.KeyRotateRightAction;
import com.jme.input.action.KeyStrafeDownAction;
import com.jme.input.action.KeyStrafeLeftAction;
import com.jme.input.action.KeyStrafeRightAction;
import com.jme.input.action.KeyStrafeUpAction;
import com.jme.renderer.Camera;

public class JOGRInputHandler extends InputHandler{
	private final float STRAFE_SPEED = 75f;
	private final float ROTATE_SPEED = 0.75f;
	public JOGRInputHandler(Camera cam, String api){
		setMouseHandler(cam);
		setKeyBindings(api);
		setActions(cam);
	}
	
	private void setMouseHandler(Camera cam){
		MouseLookHandler mouseLookHandler = new MouseLookHandler(cam, ROTATE_SPEED);
		addToAttachedHandlers(mouseLookHandler);
	}
	private void setKeyBindings(String api){
		KeyBindingManager keyboard = KeyBindingManager.getKeyBindingManager();
		
		keyboard.set("forward", KeyInput.KEY_W);
		keyboard.set("backward", KeyInput.KEY_S);
		keyboard.set("left", KeyInput.KEY_A);
		keyboard.set("right", KeyInput.KEY_D);
		keyboard.set("up", KeyInput.KEY_Q);
		keyboard.set("down", KeyInput.KEY_Z);
		keyboard.set("strafeLeft", KeyInput.KEY_LEFT);
		keyboard.set("strafeRight", KeyInput.KEY_RIGHT);
		keyboard.set("strafeUp", KeyInput.KEY_UP);
		keyboard.set("strafeDown", KeyInput.KEY_DOWN);

	}

	private void setActions(Camera cam){
		KeyBackwardAction backward = new KeyBackwardAction(cam, STRAFE_SPEED);
		addAction(backward, "backward", true);
		 
		KeyForwardAction forward = new KeyForwardAction(cam, STRAFE_SPEED);
		addAction(forward, "forward", true);
		 
		KeyRotateRightAction right = new KeyRotateRightAction(cam, ROTATE_SPEED);
		addAction(right, "right", true);
		 
		KeyRotateLeftAction left = new KeyRotateLeftAction(cam, ROTATE_SPEED);
		addAction(left, "left", true);
		 
		KeyLookDownAction down = new KeyLookDownAction(cam, ROTATE_SPEED);
		addAction(down, "down", true);
		 
		KeyLookUpAction up = new KeyLookUpAction(cam, ROTATE_SPEED);
		addAction(up, "up", true);
		 
		KeyStrafeRightAction strafeRight = new KeyStrafeRightAction(cam, STRAFE_SPEED);
		addAction(strafeRight, "strafeRight", true);
		 
		KeyStrafeLeftAction strafeLeft = new KeyStrafeLeftAction(cam, STRAFE_SPEED);
		addAction(strafeLeft, "strafeLeft", true);
		 
		KeyStrafeDownAction strafeDown = new KeyStrafeDownAction(cam, STRAFE_SPEED);
		addAction(strafeDown, "strafeDown", true);
		 
		KeyStrafeUpAction strafeUp = new KeyStrafeUpAction(cam, STRAFE_SPEED);
		addAction(strafeUp, "strafeUp", true);
		 
	}
	


}
